package 力扣;

/**
 * @author yyq
 * @create 2022-04-25 15:06
 */
public class leetcode538 {
    int sum=0;
    public TreeNode convertBST(TreeNode root) {

        if(root==null) return root;
        Reversemiddleordertraversal(root);
        return root;
    }

    private void Reversemiddleordertraversal(TreeNode root) {
        if(root.right!=null) Reversemiddleordertraversal(root.right);

        sum = root.val+sum;
        root.val= sum;

        if(root.left!=null) Reversemiddleordertraversal(root.left);

    }
}
